package test;

import com.github.dockerjava.api.command.PullImageCmd;
import common.Utils;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class PersonalCenter extends Utils {
    public static String url="http://127.0.0.1:9580/index.html";
    public PersonalCenter() {
        super(url);
    }

    //修改信息
    public void  changeInformation() throws InterruptedException {


        //登录
        LoginPage loginPage = new LoginPage();
        loginPage.login();

        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        driver.findElement(By.cssSelector("#index_user_settings")).click();

        //昵称
        driver.findElement(By.cssSelector("#setting_input_nickname")).clear();
        driver.findElement(By.cssSelector("#setting_input_nickname")).sendKeys("乾巧");
        driver.findElement(By.cssSelector("#setting_submit_nickname")).click();
        Thread.sleep(2000);

        //邮箱
        driver.findElement(By.cssSelector("#setting_input_email")).clear();
        driver.findElement(By.cssSelector("#setting_input_email")).sendKeys("3351616708@qq.com");
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#setting_submit_email")));
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#setting_submit_email")).click();
        Thread.sleep(2000);

        //电话号码
        driver.findElement(By.cssSelector("#setting_input_phoneNum")).clear();
        driver.findElement(By.cssSelector("#setting_input_phoneNum")).sendKeys("15727950817");
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#setting_submit_phoneNum")).click();
        Thread.sleep(2000);

        //个人简介
        driver.findElement(By.cssSelector("#settings_textarea_remark")).clear();
        driver.findElement(By.cssSelector("#settings_textarea_remark")).sendKeys("菜鸟111");
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#settings_submit_remark")).click();
    }

    //修改头像
    public void  profilePicture() throws InterruptedException {
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div.row.align-items-center > div:nth-child(2) > a")).sendKeys("\"C:\\Users\\树不会被夏淹没\\Desktop\\简历.jpg\"");
    }
    //修改密码
    public void changePassword() throws InterruptedException {
        driver.findElement(By.cssSelector("#settings_input_oldPassword")).sendKeys("123");
        driver.findElement(By.cssSelector("#settings_input_newPassword")).sendKeys("123");
        driver.findElement(By.cssSelector("#settings_input_passwordRepeat")).sendKeys("123");
        driver.findElement(By.cssSelector("#settings_submit_password")).click();

        String title = driver.getTitle();
        title.equals("比特论坛 - 用户登录");

        LoginPage loginPage = new LoginPage();
        loginPage.login();
    }
}
